package com.fruit.auth.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fruit.auth.dao.DepartmentDao;
import com.fruit.auth.model.Department;
import com.fruit.auth.model.User;
import com.fruit.auth.service.DepartmentService;
import com.fruit.dao.BaseDao;
import com.fruit.service.impl.BaseServiceImpl;
import com.fruit.system.model.Pager;

@Service("departmentService")
public class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService
{
	@Resource(name="departmentDao")
	private DepartmentDao departmentDao;

	@Override
	public BaseDao<Department> getEntityDao()
	{
		return departmentDao;
	}

	@Override
	public void deleteDepartment(Department department) throws ServiceException
	{
		if(departmentDao.getChildrenCount(department)>0)
			throw new ServiceException("当前机构包含下级部门，不能删除");
		departmentDao.deleteDepartment(department);
	}

	@Override
	public List<Department> findChildDepartments(Department department)
	{
		return departmentDao.findChildDepartments(department);
	}
	

	@Override
	public Pager findDepartmentUsers(Department department)
	{
		return findEntityByPager("from User u where u.department.id=?", department.getId());
	}
}
